package com.edfu.core.institutemgt.persistence.entity;

import java.util.Date;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;


@Entity
@Table(name="institute", uniqueConstraints=@UniqueConstraint(columnNames={"code"}))
public class InstituteEntity implements IInstituteMgtEntity {
	private long id;
	private String name;
	private String code;
	private String addressLine1;
	private String addressLine2;
	private String addressLine3;
	private String city;
	private String state;
	private String country;
	private String phone1;
	private String phone2;
	private String mobile;
	private String website;
	private Date createdOn;
	private Date lastModifiedOn;
	private InstituteEntity parentInstitute;
	private Set<BranchEntity> branches;
	private Set<InstituteMemberEntity> members;
	
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	public String getAddressLine1() {
		return addressLine1;
	}
	public void setAddressLine1(String addressLine1) {
		this.addressLine1 = addressLine1;
	}
	public String getAddressLine2() {
		return addressLine2;
	}
	public void setAddressLine2(String addressLine2) {
		this.addressLine2 = addressLine2;
	}
	public String getAddressLine3() {
		return addressLine3;
	}
	public void setAddressLine3(String addressLine3) {
		this.addressLine3 = addressLine3;
	}
	public String getCity() {
		return city;
	}
	public void setCity(String city) {
		this.city = city;
	}
	public String getState() {
		return state;
	}
	public void setState(String state) {
		this.state = state;
	}
	public String getCountry() {
		return country;
	}
	public void setCountry(String country) {
		this.country = country;
	}
	public String getPhone1() {
		return phone1;
	}
	public void setPhone1(String phone1) {
		this.phone1 = phone1;
	}
	public String getPhone2() {
		return phone2;
	}
	public void setPhone2(String phone2) {
		this.phone2 = phone2;
	}
	public String getMobile() {
		return mobile;
	}
	public void setMobile(String mobile) {
		this.mobile = mobile;
	}
	public String getWebsite() {
		return website;
	}
	public void setWebsite(String website) {
		this.website = website;
	}
	public Date getCreatedOn() {
		return createdOn;
	}
	public void setCreatedOn(Date createdOn) {
		this.createdOn = createdOn;
	}
	public Date getLastModifiedOn() {
		return lastModifiedOn;
	}
	public void setLastModifiedOn(Date lastModifiedOn) {
		this.lastModifiedOn = lastModifiedOn;
	}
	@ManyToOne
	@JoinColumn(name = "parent_id", nullable = true)
	public InstituteEntity getParentInstitute() {
		return parentInstitute;
	}
	public void setParentInstitute(InstituteEntity parentInstitute) {
		this.parentInstitute = parentInstitute;
	}
	
	@OneToMany(mappedBy = "institute", fetch= FetchType.EAGER)
	public Set<BranchEntity> getBranches() {
		return branches;
	}
	public void setBranches(Set<BranchEntity> branches) {
		this.branches = branches;
	}
	
	@OneToMany(mappedBy = "institute", fetch= FetchType.EAGER, cascade=CascadeType.ALL)
	public Set<InstituteMemberEntity> getMembers() {
		return members;
	}
	public void setMembers(Set<InstituteMemberEntity> members) {
		this.members = members;
	}
}
